<?php
/**
 * 设备数据相关
 * @desc
 */
class Api_Report extends PhalApi_Api {

    public function getRules() {
        return [
            'add'     => [
                'width'            => ['name' => 'width', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '设备宽度'],
                'height'           => ['name' => 'height', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '设备高度'],
                'devicePixelRatio' => ['name' => 'devicePixelRatio', 'type' => 'int', 'min' => 1, 'max' => 10, 'require' => true, 'desc' => '设备像素比'],
                'ua'               => ['name' => 'ua', 'type' => 'string', 'require' => true, 'desc' => '浏览器userAgent'],
            ],
            'lists' => [
            ]

        ];
    }

    /**
     * 设备数据添加
     * @desc 记录数据接口
     * @return int ret HTTP状态码,200成功,其他失败
     * @return int code
     * @return array data success 成功   failed 失败
     * @return string msg 提示信息
     */
    public function add() {
        $db = new Domain_Report();
        return $db->insertAndUpdate($this->width, $this->height, $this->devicePixelRatio, $this->ua) ? "success" : "failed";
    }


    /**
     * 设备数据获取
     * @desc 按times由大到小排序
     * @return int ret HTTP状态码,200成功,其他失败
     * @return int code
     * @return int width 设备宽度
     * @return int height 设备高度
     * @return int devicePixelRatio 设备像素比
     * @return string ua 浏览器userAgent
     * @return int times 同尺寸设备使用次数
     * @return string msg 提示信息
     */
    public function lists() {
        $db = new Domain_Report();
        return $db->getlist();
    }
}
